package com.ruoyi.project.system.controller;

import java.util.List;

import com.ruoyi.framework.security.service.PermissionService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.domain.BsDaily;
import com.ruoyi.project.system.service.IBsDailyService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 日报Controller
 * 
 * @author ruoyi
 * @date 2020-06-09
 */
@RestController
@RequestMapping("/system/daily")
public class BsDailyController extends BaseController
{
    @Autowired
    private IBsDailyService bsDailyService;
    @Autowired
    private PermissionService permissionService;
    /**
     * 查询日报列表
     */
    @PreAuthorize("@ss.hasPermi('system:daily:list')")
    @GetMapping("/list")
    public TableDataInfo list(BsDaily bsDaily)
    {
        System.out.println("+++++++++++++++"+permissionService.hasPermi("system:daily:list"));
        startPage();
        List<BsDaily> list = bsDailyService.selectBsDailyList(bsDaily);
        return getDataTable(list);
    }

    /**
     * 导出日报列表
     */
    @PreAuthorize("@ss.hasPermi('system:daily:export')")
    @Log(title = "日报", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BsDaily bsDaily)
    {
        List<BsDaily> list = bsDailyService.selectBsDailyList(bsDaily);
        ExcelUtil<BsDaily> util = new ExcelUtil<BsDaily>(BsDaily.class);
        return util.exportExcel(list, "daily");
    }

    /**
     * 获取日报详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:daily:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(bsDailyService.selectBsDailyById(id));
    }

    /**
     * 新增日报
     */
    @PreAuthorize("@ss.hasPermi('system:daily:add')")
    @Log(title = "日报", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BsDaily bsDaily)
    {
        return toAjax(bsDailyService.insertBsDaily(bsDaily));
    }

    /**
     * 修改日报
     */
    @PreAuthorize("@ss.hasPermi('system:daily:edit')")
    @Log(title = "日报", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BsDaily bsDaily)
    {
        return toAjax(bsDailyService.updateBsDaily(bsDaily));
    }

    /**
     * 删除日报
     */
    @PreAuthorize("@ss.hasPermi('system:daily:remove')")
    @Log(title = "日报", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(bsDailyService.deleteBsDailyByIds(ids));
    }
}
